﻿using Microsoft.Practices.Unity;
using System;

namespace WinRT.SIP.UI.Common
{
    public static class ServiceLocator
    {
        private static readonly IUnityContainer _container = new UnityContainer();

        public static void RegisterInstance<TInterface>(TInterface instance)
        {
            _container.RegisterInstance<TInterface>(instance);
        }

        public static void RegisterInstanceAsSingleton<TFrom, TTo>()
            where TTo : TFrom
        {
            _container.RegisterType<TFrom, TTo>(new ContainerControlledLifetimeManager());
        }

        public static object Resolve(Type t)
        {
            return _container.Resolve(t);
        }

        public static T Resolve<T>()
        {
            return _container.Resolve<T>();
        }
    }
}
